package org.jeecg.modules.wlhy.utils;

import org.apache.commons.lang.StringUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.modules.wlhy.bill.entity.HyBill;
import org.jeecg.modules.wlhy.shipping.entity.HyShippingNote;

//检查单据状态工具类
public class HyStatusCheckUtil {
    //运费支付方式(1按运单结算2车队长结算 3预付运费)
    public static boolean checkPayType(String payType) {
        if ("1".equals(payType) || "2".equals(payType) || "3".equals(payType)) {
            return true;
        }
        throw new JeecgBootException("支付方式错误");
    }
    //运费支付方式(1按运单结算2车队长结算 3预付运费)
    public static boolean checkPlanFee_PayType(String payType) {
        if ("1".equals(payType) || "2".equals(payType)) {
            return true;
        }
        throw new JeecgBootException("支付计划:运费支付方式只支持按运单结算");
    }

    // 运费计算方式(1单价4包车价)
    public static boolean checkShippingType(String shippingType) {
        if ("1".equals(shippingType) || "4".equals(shippingType)) {
            return true;
        }
        throw new JeecgBootException("运费计算方式错误,请核实运单信息");
    }

    //亏损方式
    public static boolean checkLossType(String lossType) {
        if ("1".equals(lossType) || "2".equals(lossType)) {
            return true;
        }
        throw new JeecgBootException("亏损方式错误,请核实运单信息");
    }

    //订单模式(1管理费模式2撮合模式3差价模式)
    public static boolean checkOrderMode(String orderMode) {
        if ("1".equals(orderMode) || "3".equals(orderMode) || "4".equals(orderMode)) {
            return true;
        }
        throw new JeecgBootException("订单模式错误");
    }


    //订单模式(1管理费模式2撮合模式3差价模式)
    public static boolean checkPlanFee_OrderMode(String orderMode) {
        if ("1".equals(orderMode) || "3".equals(orderMode)|| "4".equals(orderMode)) {
            return true;
        }
        throw new JeecgBootException("订单模式错误");
    }

    public static boolean checkOrderMode2(String orderMode) {
        if ("1".equals(orderMode) || "2".equals(orderMode) || "3".equals(orderMode)|| "4".equals(orderMode)) {
            return true;
        }
        throw new JeecgBootException("订单模式错误");
    }

    public static void checkShippingNoteCustomerId(HyShippingNote shippingNote, String customerId) {
        String orderMode = shippingNote.getOrderMode();
        checkOrderMode(orderMode);
        if("3".equals(orderMode)){
            if (!StringUtils.equals(customerId, shippingNote.getCustomerId()) && !StringUtils.equals(customerId, shippingNote.getAgentId())) {
                throw new JeecgBootException("运单数据错误");
            }
        }else {
            if (!StringUtils.equals(customerId, shippingNote.getCustomerId())) {
                throw new JeecgBootException("运单数据错误");
            }
        }
    }

    public static void checkBillCustomerId(HyBill bill, String customerId) {
        if (!StringUtils.equals(customerId, bill.getCustomerId()) && !StringUtils.equals(customerId, bill.getAgentId())) {
            throw new JeecgBootException("运单数据错误");
        }
    }
}
